﻿package kit4j.tests.jdk.lang.string;

import java.util.Formatter;

public class Receipt2 extends Receipt {
	
	private Formatter formatter;
	
	private String itemTitle;
	
	private String quantityTitle;
	
	private String priceTitle;
	
	private String totalTitle;
	
	private int itemWidth;
	
	private int itemMaxSize;
	
	private int quantityWidth;
	
	private int priceWidth;
	
	private int pricePrecision;
	
	private double total;
	

	public Receipt2() {
		this(new Formatter(System.out));
	}
	
	public Receipt2(Formatter formatter) {
		this.formatter = formatter;
		
		total = 0;
	}
	
	public void printTitle() {
		formatter.format("%-35s %5s %10s\n", 
				itemTitle, quantityTitle, priceTitle);
		formatter.format("%-35s %5s %10s\n",
				"----", "---", "-----");
	}
	
	public void print(String itemName, int qty, double price) {
		formatter.format("%-35.35s %5d %10.2f\n",
				itemName, qty, price);
		
		total += price;
	}
	
	public void printTotal() {
		formatter.format("%-35.35s %5s %10s\n", 
				"", "", "-----");
		formatter.format("%-35.35s %5s %10.2f\n", 
				totalTitle, "", total);
	}

	public Formatter getFormatter() {
		return formatter;
	}

	public void setFormatter(Formatter formatter) {
		this.formatter = formatter;
	}

	public String getItemTitle() {
		return itemTitle;
	}

	public void setItemTitle(String itemTitle) {
		this.itemTitle = itemTitle;
	}

	public String getQuantityTitle() {
		return quantityTitle;
	}

	public void setQuantityTitle(String quantityTitle) {
		this.quantityTitle = quantityTitle;
	}

	public String getPriceTitle() {
		return priceTitle;
	}

	public void setPriceTitle(String priceTitle) {
		this.priceTitle = priceTitle;
	}

	public String getTotalTitle() {
		return totalTitle;
	}

	public void setTotalTitle(String totalTitle) {
		this.totalTitle = totalTitle;
	}

	public int getItemWidth() {
		return itemWidth;
	}

	public void setItemWidth(int itemWidth) {
		this.itemWidth = itemWidth;
	}
	
	public int getItemMaxSize() {
		return itemMaxSize;
	}
	
	public void setItemMaxSize(int itemMaxSize) {
		this.itemMaxSize = itemMaxSize;
	}

	public int getQuantityWidth() {
		return quantityWidth;
	}

	public void setQuantityWidth(int quantityWidth) {
		this.quantityWidth = quantityWidth;
	}

	public int getPriceWidth() {
		return priceWidth;
	}

	public void setPriceWidth(int priceWidth) {
		this.priceWidth = priceWidth;
	}

	public int getPricePrecision() {
		return pricePrecision;
	}

	public void setPricePrecision(int pricePrecision) {
		this.pricePrecision = pricePrecision;
	}
	
}
